package com.wfh.adapter;

import com.wfh.R;
import com.wfh.activity.ProductActivity;

import android.content.Context;
import android.content.Intent;
import android.sax.StartElementListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

public class GridAdapter extends BaseAdapter {
	private Context mcontext;

	public GridAdapter(Context context) {
		this.mcontext = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return str.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(mcontext);
		View main = inflater.inflate(R.layout.adapter_grid, null);
		TextView textview = (TextView) main.findViewById(R.id.textView1);
		textview.setText(str[position]);
		
		final Intent intent=new Intent();
		switch (str[position]) {
			case R.string.tejia:
				intent.putExtra("action", "weeks");
				break;
			case R.string.xianshi:
				intent.putExtra("action", "promotions");
				break;
			case R.string.rexiao:
				intent.putExtra("action", "hots");
				break;
			case R.string.newp:
				intent.putExtra("action", "bests");
				break;
			default:
				break;
		}
		main.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				intent.setClass(mcontext, ProductActivity.class);
				mcontext.startActivity(intent);
			}
		});

		return main;
	}

	Integer[] str = new Integer[] { R.string.xianshi, R.string.tejia,
			R.string.rexiao, R.string.newp };

}
